﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ClassLibrary.Entity;
using ClassLibrary.DAO;
using System.Data;

public partial class Admin_ucControl_ucPopup : System.Web.UI.UserControl
{
    TblPopupDAO popupDAO = new TblPopupDAO(Global.CONNECTION_STRING);

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadPopup();
            string id = Request.QueryString["id"];
            if (id != "" || id != null)
            {
                loadDetail();
            }
        }
    }

    private void loadDetail()
    {
        string id = Request.QueryString["id"];
        if (id != null || id != "")
        {
            DataTable dt = popupDAO.GetPopup_ByID(Global.ConvertToInt(id));
            foreach (DataRow dr in dt.Rows)
            {
                FCKPopup.Value = dr["NoiDung"].ToString();
            }
        }
    }

    private void LoadPopup()
    {
        grdPopup.DataSource = popupDAO.GetPopup();
        grdPopup.DataBind();
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        bool flag = false;
        try
        {
            TblPopup poup = new TblPopup();
            poup.NoiDung = FCKPopup.Value;

            string id = Request.QueryString["id"];
            if (id == "" || id == null)
            {
              //  popupDAO.InsPopup(poup, 1);
            }
            else
            {
                poup.ID = Global.ConvertToInt(id);
                popupDAO.InsPopup(poup, 2);
            }

            flag = true;
        }
        catch (Exception ex)
        {
            throw ex;
        }

        if (flag)
        {
            FCKPopup.Value = string.Empty;
            LoadPopup();
        }
    }
}